<!DOCTYPE html>
<html dir="ltr">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" type="image/png" sizes="16x16" href="./assets/images/favicon.png">
    <title>图书管理系统</title>
    <link href="./dist/css/style.min.css" rel="stylesheet">
    <script src="./assets/libs/jquery/dist/jquery.min.js"></script>

    <script src="./assets/libs/popper.js/dist/umd/popper.min.js"></script>
    <script src="./assets/libs/bootstrap/dist/js/bootstrap.min.js"></script>
<!--    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>-->
<!--    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>-->

</head>

<body>
<div class="main-wrapper">


    <div class="auth-wrapper d-flex no-block justify-content-center align-items-center bg-dark">
        <div class="auth-box bg-dark border-top border-secondary">
            <div>
                <div class="text-center p-t-20 p-b-20">
                    <span class="db"><img src="./assets/images/logo.png" alt="logo" /></span>
                </div>
                <!-- Form -->
                <form class="form-horizontal m-t-20" id="loginform" action="index.html">
                    <div class="row p-b-30">
                        <div class="col-12">
                            <div class="input-group mb-3">
                                <div class="input-group-prepend">
                                    <span class="input-group-text bg-success text-white"><i class="ti-user"></i></span>
                                </div>
                                <input type="text" id="name" class="form-control form-control-lg" placeholder="Username" aria-label="Username" aria-describedby="basic-addon1" required="">
                            </div>
                            <div class="input-group mb-3">
                                <div class="input-group-prepend">
                                    <span class="input-group-text bg-warning text-white" id="basic-addon2"><i class="ti-pencil"></i></span>
                                </div>
                                <input type="password" id="password" class="form-control form-control-lg" placeholder="Password" aria-label="Password" aria-describedby="basic-addon1" required="">
                            </div>
                        </div>
                    </div>
                    <div class="row border-top border-secondary">
                        <div class="col-12">
                            <div class="form-group">
                                <div class="p-t-20">
                                    <button class="btn btn-info" id="to-manage" onclick="tologin()" type="button">我是读者</button>
                                    <button class="btn btn-success float-right" onclick="login()" type="button">登录</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>

</div>

<script type="text/javascript">
    function tologin() {
        window.open("index.html","_self")
    }
    function login(){
        var name = $("#name").val();
        var password = $("#password").val();
        $.ajax({
            type:"POST",
            url:"/administrators/login",
            data:{
                name:name,
                password:password
            },
            dataType:"json",
            success:function(result){
                if (result){

                    document.cookie="id=" + result.userId + ";path=/";
                    sessionStorage.setItem("name", name);
                    sessionStorage.setItem("password", password);
                    alert("登陆成功!");
                    window.open("manage.html","_self");
                }else {
                    alert("账号或密码错误，请重新输入!");
                    window.location.reload();
                }
            }
        });
    }
</script>
</body>
</html>